package com.dingding.action;

import org.apache.log4j.Logger;

import com.dingding.common.core.config.SystemConfig;
import com.dingding.common.core.config.SystemConfig.OrderPushStatusEnum;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.encrpt.RSACoder;

/**
 * 
 * @ClassName: DispatchAction
 * @Description:手机端请求总调度类（所有的手机端请求都进入到当前类）
 * @author cheShaowei
 * @date 2015-7-1 下午03:25:20
 * @version 叮叮搭车V2.0
 * 
 */
@SuppressWarnings("all")
public class DispatchAction extends BaseAction {

	private static final Logger log = Logger.getLogger(DispatchAction.class);

	private static final long serialVersionUID = 4635658633712840936L;

	/**
	 * 
	 * @Title: excuteDispatch
	 * @Description:action执行调度类
	 * @author cheShaoWei
	 * @throws
	 * 
	 */
	public String excuteDispatch() throws Exception {

		// 获取客户端请求数据
		String requestJsonData = super.getClientData();

		// 执行解密
		String encodData = RSACoder.decryptByPrivateKey(requestJsonData);
		
		// 执行业务调用，并获取返回数据
		String responseJsonData = super.requestDispatchProxy.modularExcute(encodData);
		
		log.info("响应给客户端数据为：" + responseJsonData);

		// 加密
		String encryptData = RSACoder.encryptByPublicKey(responseJsonData);

		// 将数据返回给客户端
		super.write(encryptData);

		return NONE;
	}

	/**
	 * @Title: updatePushStatus 
	 * @Description: 管理后台推送开关控制服务(临时用)
	 * @author CHEHAUNBO
	 */
	public String updatePushStatus() {

		// 获取客户端请求数据
		String requestJsonData = super.getClientData();
		if (ToolUtil.isNotBlank(requestJsonData)) {
			if (OrderPushStatusEnum.ON.toString().equals(requestJsonData)) { // 开启同城推送
				SystemConfig.setOrderPushStatus(OrderPushStatusEnum.ON);
			} else if (OrderPushStatusEnum.OFF.toString().equals(requestJsonData)) { // 关闭同城推送
				SystemConfig.setOrderPushStatus(OrderPushStatusEnum.OFF);
			}
			super.write("success");
		} else {
			super.write("error");
		}

		return NONE;

	}

	/**
	 * 
	 * @Title: getPushStatus 
	 * @Description: 获取订单推送当前开关状态
	 * @return String  null
	 * @author CHEHAUNBO
	 */
	public String getPushStatus() {

		super.write(SystemConfig.getOrderPushStatus().toString());

		return NONE;

	}

}
